package com.study.java.jinjie.GUI.binary.ui;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import static com.study.java.jinjie.GUI.binary.ui.Setting.Window_confirmExit;

/**
 * @Author: MuMu
 * @Date: 2024/4/7 19:40
 */
public class MainWindowListener extends WindowAdapter {
    private JFrame jFrame;

    public MainWindowListener(JFrame jFrame) {
        this.jFrame = jFrame;
    }

    @Override
    public void windowClosing(WindowEvent e) {
        confirmExit(); // 在窗口关闭时调用确认退出方法
    }

    private void confirmExit() {
        if (Window_confirmExit) {
            int confirmed = JOptionPane.showConfirmDialog(null,
                    "确定要退出吗？", "退出确认",
                    JOptionPane.YES_NO_OPTION);

            if (confirmed == JOptionPane.YES_OPTION) {
                jFrame.dispose(); // 退出应用程序
            }
        }
    }
}
